﻿
#include "pch.h"
#include "MysqlConn.h"

struct City
{
    std::string id;
    std::string code;
    std::string name;
    static std::vector<InputLayout> inputLayout;
};

std::vector<InputLayout> City::inputLayout =
{
    {"id", offsetof(City, id)},
    {"code", offsetof(City,code)},
    {"name", offsetof(City, name)}
};



int main()
{
    MysqlConn::Init();
    MysqlConn::Desc desc;
    MysqlConn conn;
    if (!conn.Create(desc))
    {
        LOGE("Failed create mysql connection");
        return -1;
    }

    std::vector<City> citys;
    if (!conn.Query("SELECT * FROM t_demo_city", citys))
    {
        return -1;
    }
    else
    {
        for (const auto& c : citys)
        {
            LOGI("Id %s name %s code %s", c.id.c_str(), c.name.c_str(), c.code.c_str());
        }
    }
    //MysqlConn::Res res;
    //if (!conn.Query("SELECT * FROM t_demo_city", res))
    //{
    //    LOGE("failed to query");
    //    return -1;
    //}
    //for (auto d : res.header)
    //{
    //    printf("%s \t", d.c_str());
    //}
    //printf("\n");
    //for (auto& row : res.rows)
    //{
    //    for (auto d : row.data)
    //    {
    //        printf("%s\t", d.c_str());
    //    }
    //    printf("\n");
    //}

    //if (!conn.Query("delete from t_demo_curd where id=\"ssss\""))
    //{
    //    LOGE("failed to query");
    //    return -1;
    //}
    
    conn.Close();


    return -1;
}
